<?php
header('Content-type: application/vnd.ms-excel');
header("Content-Disposition: attachment; filename=Reporte_mensajes_enviados_".date('d-m-Y').".xls");
header("Pragma: no-cache");
header("Expires: 0");
$fecha_ini=$_GET['ini'];
$fecha_fin=$_GET['fin'];
echo "<br/>";
echo "<br/>";


echo "<table border=0 align=\"center\">";
echo "<th>";
echo "<tr><td>"; 
echo "<img src=http://localhost/A2PF/graficos/exporting-server/temp/slash123.jpg> ";
echo"</td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr>";
echo "<tr><td></td></tr></table>";




echo "<table border=0 align=\"center\">";
echo "<thead >";
echo "<tr>";
//indicas los nombres de las columnas

echo "<th bgcolor='#0277BD' style='color:white' >Fecha</th>";
echo "<th bgcolor='#0277BD' style='color:white'>Claro</th>";
echo "<th bgcolor='#0277BD' style='color:white' >Movistar</th>";



///////////////////////////////////////7


echo "</tr>";
echo "</thead>";
echo "<tbody>";

$link = mysql_connect("localhost", "admin", "Xurpas123");
mysql_select_db("smsnic",$link);

//escribes tu consulta
$result1= mysql_query("SELECT fecha, IFNULL( 
CASE WHEN t.`operadora_id` =2
THEN COUNT( * ) 
END , 0 ) AS Claro, IFNULL( 
CASE WHEN t.`operadora_id` =1
THEN COUNT( * ) 
END , 0 ) AS Movistar
FROM  `envios` e
INNER JOIN  `telefonos` t ON ( e.`id_telefono` = t.`id` ) 
where e.`fecha` > '".$fecha_ini."' and e.`fecha` < '".$fecha_fin."'
group by e.`fecha`", $link) or die(mysql_error());

if(mysql_num_rows($result1)) {
	while( $cliente = @mysql_fetch_array($result1) ){



///cambias el nombre de los campos segun el resultado de la consulta, estos deberian ser los mismos que colocastes arriba
echo "<tr>";
echo "<td align=\"center\" valign=\"middle\">".$cliente['fecha'];
echo "</td>";
echo "<td align=\"center\" valign=\"middle\">".$cliente['Claro'];
echo "</td>";
echo "<td align=\"center\" valign=\"middle\">".$cliente['Movistar'];
echo "</td>";
echo "</tr><br /><br /><br /><br /></table><table border=0>";

	}
}


echo "</tbody>";
echo "</table>";   

?>
